/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.deib.se2.meteocal.business.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.validation.constraints.NotNull;

@Entity(name = "EVENTS")
public class Event implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @NotNull
    private Long id;
    
    @NotNull(message = "May not be empty")
    private String title;
    
    private boolean outdoor;
    
    private int badWeatherLevel;
    
    //event has one user creator
    @ManyToOne
    @JoinColumn(name = "creator", referencedColumnName = "email")
    private User creator;
    
    //event has one location
    @ManyToOne
    @JoinColumn(name = "idlocation", referencedColumnName = "id")
    private Location idLocation;
    
    //event has many calendars
    @ManyToMany(mappedBy="eventCollection")
    private Collection<Calendar> calendar;
    
    //event has many invitations
    @OneToMany(mappedBy="referingEvent")
    private List<Invitation> invitations;
    
    //event has many notifications
    @OneToMany(mappedBy="referingEvent")
    private List<Notification> notifications;
    
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date startDate;
    
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date endDate;
    
    private boolean isPublic;

    public Event(){
        calendar = new ArrayList<Calendar>();
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return isOutdoor
     */
    public boolean isOutdoor() {
        return outdoor;
    }

    /**
     * @param outdoor the outdoor to set
     */
    public void setOutdoor(boolean outdoor) {
        this.outdoor = outdoor;
    }

    /**
     * @return the bedWeatherLevel
     */
    public int getBadWeatherLevel() {
        return badWeatherLevel;
    }

    /**
     * @param badWeatherLevel the bedWeatherLevel to set
     */
    public void setBadWeatherLevel(int badWeatherLevel) {
        this.badWeatherLevel = badWeatherLevel;
    }

    /**
     * @return the creator
     */
    public User getCreator() {
        return creator;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(User creator) {
        this.creator = creator;
    }

    /**
     * @return the idLocation
     */
    public Location getIdLocation() {
        return idLocation;
    }

    /**
     * @param idLocation the idLocation to set
     */
    public void setIdLocation(Location idLocation) {
        this.idLocation = idLocation;
    }

    /**
     * @return the startDate
     */
    public Date getStartDate() {
        return startDate;
    }

    /**
     * @param startDate the startDate to set
     */
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @return the isPublic
     */
    public boolean getIsPublic() {
        return isIsPublic();
    }

    /**
     * @param isPublic the isPublic to set
     */
    public void setIsPublic(boolean isPublic) {
        this.isPublic = isPublic;
    }

    /**
     * @return the calendar
     */
    public Collection<Calendar> getCalendar() {
        return calendar;
    }

    /**
     * @param calendar the calendar to set
     */
    public void setCalendar(Collection<Calendar> calendar) {
        this.calendar = calendar;
    }

    /**
     * @param calendar the calendars to set
     */
    // Calendar calendar del metodo nel caso deve tornare una collection<Calendar>
    public void setCalendar(Calendar calendar) {
        this.getCalendar().add(calendar);
    }
    
    /**
     * @return the invitations
     */
    public List<Invitation> getInvitations() {
        return invitations;
    }

    /**
     * @param invitations the invitations to set
     */
    public void setInvitations(List<Invitation> invitations) {
        this.invitations = invitations;
    }

    /**
     * @return the notifications
     */
    public List<Notification> getNotifications() {
        return notifications;
    }

    /**
     * @param notifications the notifications to set
     */
    public void setNotifications(List<Notification> notifications) {
        this.notifications = notifications;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the isPublic
     */
    public boolean isIsPublic() {
        return isPublic;
    }
 
}
